import {defineStore} from "pinia";
import {ref} from "vue";
import myAxios from "../plugins/myAxios.ts";

export const useAdminStore = defineStore('adminUser', () => {
    const adminUser = ref({})

    const getAdminUser = async () => {
        const res = await myAxios.get('/admin/get/login');
        if (res.code === 40100) {
            adminUser.value = '未登录'
            console.log('未登录')
        } else {
            adminUser.value = res.data
        }
    }
    const adminLogout = () => {
        myAxios.post('/admin/logout').then(res => {
            if (res.code === 0) {
                console.log('退出成功')
                adminUser.value = '未登录'
            }
        })
    }
    const setAdminUser = (userInfo: any) => {
        adminUser.value = userInfo
    }

    return {adminUser, getAdminUser, setAdminUser, adminLogout}
})
